from devicetest.api import Asserts
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Calculator


class PreTest_RK3568_Tooling_Calculator_0200(TestCase, Calculator):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面-计算器应用
    # 测试步骤：
    # 各数字与运算符计算
    # 预期结果：
    # 正常运行各种计算，结果准确

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):

        Step('步骤1：进入计算器应用，各数字与运算符计算')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 2)
        try:
            CommonOH.touchByText(self.Phone1, '允许')
        except:
            pass
        for exp in ['1+2', '3-4', '5*6', '8/2']:
            # 3*5=15
            CommonOH.touchByKey(self.Phone1, exp[0])
            CommonOH.touchByKey(self.Phone1, exp[1])
            CommonOH.touchByKey(self.Phone1, exp[2])
            CommonOH.touchByKey(self.Phone1, '=')
            Step('预期结果1：正常运行各种计算，结果准确')
            result = CommonOH.getTextByCondition(self.Phone1, 'key/expression')
            Asserts.assert_equal(int(float(result)), int(eval(exp)))
            CommonOH.touchByKey(self.Phone1, 'C')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
